package com.baizhi.controller;

import com.baizhi.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("admin")
public class AdminController {
    @Autowired
    private AdminService adminService;
    @RequestMapping("login")
    public Map login(HttpSession session,String username,String password,String code){
        System.out.println("code="+code);
        Map map = new HashMap();
        String realcode = (String) session.getAttribute("validatecode");
        System.out.println("realcode="+realcode);
        if(realcode!=null && realcode.equals(code)){
            boolean b = adminService.login(username, password);
            if(b){
                session.setAttribute("login",username);
                map.put("flag",true);
            }else {
                map.put("flag",false);
            }
        }else {
            map.put("flag",false);
        }
        return map;
    }
}
